//===========平台客户管理.js


// 获取页签权限
function getTabs() {
    let token = localStorage.getItem('token') || '';
    let authorityList = new Array();
    Object.keys(h3ui.widgets).filter(item => item.includes('TabsContainer')).map(tabsContainer =>
        h3ui.widgets[tabsContainer].childIds.map(tab =>
            authorityList.push(tab)
        ));
    let appCode = h3ui.$router.currentRoute.params.appCode;
    let pageCode = h3ui.$router.currentRoute.query.pageCode;
    let param = {
        data: {
            appCode: appCode,
            pageCode: pageCode
        }
    }
    h3ui.axios({
        method: 'post',
        url: '/api/launcher/systemmanagement/application/invoke?action=/UserTabsService/getUserTabsByAppCodeAndPageCode',
        data:param,
        headers: {
            Authorization: `Bearer ${token}`
        }
    }).then(function (res) {
        if (res.status == 200) {
            for (let authority of authorityList) {
                let result = res.data.data.find(tab => tab === authority);
                if (!result) {
                    h3ui.designerApp.apply({
                        type: 'remove',
                        data: { id: authority }
                    })
                }
            }
        }
    }).catch(function (error) {
        h3ui.$message.error(error);
    });
}

//===========公共
/**
 *  跳转表单页面并url携带参数
 *  pageCode // 页面code *
 *  param    // 参数
 *  appCode  // 应用code
 */
function toModePage(pageCode, param, appCode) {
    // 获取页面url地址
    let url = window.location.href.substring(0, window.location.href.indexOf('?'));

    if (appCode) {
        url = url.replaceAll(h3ui.appInfo.appCode, appCode);
    }

    var paramstr = Object.keys(param).map(a => {
        return "&".concat(a).concat("=").concat(param[a])
    }).join("");

    // 跳转创建页面
    window.location.href = url + '?pageCode=' + pageCode + paramstr;
}


//删除事件
function deletes(evt) {
    console.log(evt);
    var keys = evt.data.keys;
    var schemaCode = evt.node.props.bindingModel.schemaCode;
    var listId = evt.node.id;
    if (keys.length < 1) {
        h3ui.$message.info("请勾选行数据");
        return;
    }
    h3ui.models[schemaCode].batchDeleteBO({bizObjectIds: keys}).then(() => {
        h3ui.$message.info('成功');
        // 刷新页面
        reloadList(listId);
    });
}


//触发列表刷新事件
function reloadList(fromListId) {
    doReloadList({pageIndex: 1, node: {id: fromListId}});
}

//列表刷新
function doReloadList(evt) {
    var list = h3ui.widgets[evt.node.id];

    var queryId = list.childIds.find(a => a.includes("ModelQueryForm"));

    var filter = h3ui.widgets[queryId].props.value || {};

    filter = JSON.parse(JSON.stringify(filter));


    var pageId = list.childIds.find(a => a.includes("Pagination"));

    var pageIndex = h3ui.widgets[pageId].props.current;
    var pageSize = h3ui.widgets[pageId].props.pageSize;

    list.emit("load", {pageIndex, pageSize, filter});

    list.props.selectedRowKeys = [];
    list.props.selectedRow = [];

}


// 封装了axiosService 方便调用其他应用的服务
const axiosService = function (url, param) {
    return new Promise(function (resolve, reject) {
        h3ui.axios({
            method: 'post',
            url,
            data: param,
            headers: {
                Authorization: 'Bearer ' + localStorage.getItem("token"),
                'Content-Type': 'application/json;charset=UTF-8'
            }
        }).then(function (res) {
            console.log(res);

            if (res.status == 200) {
                resolve(res.data);
            } else {
                reject(res);
            }
        }).catch(function (error) {
            h3ui.$message.error(error);
        });
    })
}


//=============页面进入事件


//=======平台客户=================

//打开平台客户绑定弹框
function openPlatModal(evt) {
    console.log(evt);
    //按钮名称和按钮code
    var {name, code} = evt.data;
    //列表id
    var listId = evt.node.id;
    //弹框对象
    var modal = h3ui.widgets.CustomModal5;
    //领域对象
    var dataSource = h3ui.models.t_platform_grant_user;
    dataSource.newItem();//初始化

    if ("openAdd" == code) {
        console.log("打开创建绑定弹框");


    } else if ("openUpdate" == code) {
        console.log("打开修改绑定弹框");

        if (evt.node.props.selectedRow.length == 0) {
            h3ui.$message.info("请勾选数据");
            return;
        }

    } else {
        return;
    }


//设定输入框为必填
    h3ui.widgets.FormModelItem82.props.required = true;
    h3ui.widgets.FormModelItem83.props.required = true;

    h3ui.widgets.FormModelItem82.props.visible.display = ("openAdd" == code ? "" : "none");
    modal.props.title = name;
    modal.props.visible = true;

}

//提交平台客户关系
function submitPlatRole(evt) {
    debugger;
    var dataSource = h3ui.models.t_platform_grant_user;
    var modal = h3ui.widgets.CustomModal5;
    var listId = "FormList3";

    var title = modal.props.title;



    if (title == "创建平台客户关系") {
        //如果没有填写的话,提示
        if (!platformValueConvent(dataSource.item)){
            h3ui.$message.error("请填写数据");
            return;
        }
        dataSource.createBO().then(res => {
            h3ui.$message.info("提交成功");
            reloadList(listId);
            modal.props.visible = false;
        });


    } else if (title == "修改平台客户关系") {
        var items = JSON.parse(JSON.stringify(h3ui.widgets[listId].props.selectedRow));
        items.forEach(a => a.member_id = dataSource.item.member_id);
        let flag=true;
        items.forEach(a=>{
            if (!platformValueConvent(a)){
                flag=false;
            }
        })

        if (!flag){
            h3ui.$message.error("请填写数据");
            return;
        }
        //items.forEach(platformValueConvent);
        items.forEach(a => dataSource.convert(a, dataSource.schema));
        var url = "/api/launcher/operation1center/application/invoke?action=/ApplicationService/updateBO";
        var param = {schemaCode: dataSource.schemaCode, data: items};

        axiosService(url, {schemaCode: dataSource.schemaCode, data: items})
            .then(res => {
                if (res.success) {
                    reloadList(listId);
                    modal.props.visible = false;
                } else {
                    h3ui.$message.info(res.errMessage || "修改失败")
                }
            })


    } else {
        return;
    }

}

//平台关系其他值设置
function platformValueConvent(item) {
    //是否填写组织
    let orgFlag=false;
    //是否填写人员
    let  memFlag=false;
    if (item.organization_id && item.organization_id.length > 0) {
        item.organization_name = item.organization_id[0].name;
        orgFlag=true;
    }

    if (item.member_id && item.member_id.length > 0) {
        item.member_name = item.member_id[0].name;
        item.department_id = item.member_id[0].departmentId;
        memFlag=true;
    }
    if (!orgFlag || !memFlag){
        return false;
    }
    return true;
}


//====需求列表===========


//列表加载事件-前置条件
function demandpoolList(evt) {

    console.log(evt);


    var list = h3ui.widgets[evt.node.id];

    var queryId = list.childIds.find(a => a.includes("ModelQueryForm"));

    var filter = h3ui.widgets[queryId].props.value || {};

    filter = JSON.parse(JSON.stringify(filter));
    //新建和已退回的
    filter.demand_pool_status = ["0", "2"];

    var pageId = list.childIds.find(a => a.includes("Pagination"));

    var pageIndex = h3ui.widgets[pageId].props.current;
    var pageSize = h3ui.widgets[pageId].props.pageSize;

    var schemaCode = list.props.bindingModel.schemaCode;

    h3ui.models[schemaCode].listBO({pageIndex, pageSize, filter}).then(res => {

        list.props.dataSource = res;

    })

}


// 跳转到需求修改页面
function toUpdateDemandPool(evt) {

    var rows = h3ui.widgets.FormList5.props.selectedRow;

    if (rows.length == 0) {
        h3ui.$message.info('请选择一行');
        return;
    } else if (rows.length > 1) {
        h3ui.$message.info('仅能选择一行');
        return;
    }

    var row = rows[0];

    var val = row.id;

    var appCode = "demandpool";
    var pageCode = "createDemandPool";
    var mode = "update";
    var param = {
        clickcloumn: val,
        mode: mode,
        link: "platform_cust_mana"
    };

    toModePage(pageCode, param, appCode);

}

function updateDemandPoolStatus(evt) {
    console.log("updateDemandPoolStatus");
    var keys = h3ui.widgets.FormList5.props.selectedRowKeys;

    if (keys.length == 0) {
        h3ui.$message.info('请选择数据');
        return;
    }

    var demandPoolIdList = keys;

    h3ui.$confirm({
        title: '确认提交吗',
        onOk() {
            var url = "/api/launcher/demandpool/application/invoke?action=/DemandPoolService/updateDemandPoolStatus";

            axiosService(url, {demandPoolIdList}).then(res => {
                if (res.success) {
                    h3ui.$message.info('提交成功');
                    reloadList("FormList5");

                } else {
                    h3ui.$message.error(res.errMessage || '提交失败');
                }

            })
        }
    });


}


//===询价列表================

function toMidflyInquirList() {

    var list = h3ui.widgets.FormList6.props;

    var rows = list.selectedRow;

    if (rows.length != 1) {
        h3ui.$message.info("请勾选一条数据");
        return;
    }
    var row = rows[0];
    if (row.inquiry_goods_status != 0) {
        h3ui.$message.info("仅新建的询价单可以修改");
        return;
    }

    var inquiry_id = row.inquiry_id[0].id;
    debugger;
    var appCode = "sourcingcenter";
    var pageCode = "inquiry_new";
    var mode = "update";
    var param = {
        clickcloumn: inquiry_id,
        mode: mode,
        link: "platform_cust_mana"
    };

    toModePage(pageCode, param, appCode);
}


function showAttachment(evt) {
    console.log(evt);

    if (evt.data.action == "附件") {
        var attachment = evt.data.row.attachment;

        if (attachment) {
            h3ui.widgets.Upload2.props.value = Object.assign([], attachment);

            if (h3ui.widgets.Upload2.props.value) {
                h3ui.widgets.Upload2.props.value.map(b => {
                    b.uid = b.id;
                    b.status = "done";
                    b.url = "/api/file/download?refId=" + b.id;
                })
            }


        }

        h3ui.widgets.Upload2.props.readonly = true
        h3ui.widgets.CustomModal1.props.visible = true;
    }


}


///==============成本中心===========


// 打开成本中心新增对话框
function openCreateCenterModel() {


    h3ui.models.t_cost_center.newItem();

    h3ui.widgets.CustomModal2.props.title = "新增成本中心";

    h3ui.widgets.CustomModal2.props.visible = true;

    //表单必填表示,添加list
    let filedRequest=['FormModelItem26','FormModelItem27','FormModelItem28'];

    //模型领域字段必填
    let modelRequest=['organization_id','member_id','name'];


    setRequest(filedRequest,modelRequest,'t_cost_center');
}

// 打开修改成本中心对话框
function openUpdateCenterModel() {

    var rows = h3ui.widgets.FormList7.props.selectedRow;

    if (rows.length != 1) {
        h3ui.$message.info("请选择仅一条数据");
        return;
    }

    h3ui.models.t_cost_center.newItem();

    h3ui.models.t_cost_center.item = rows[0];
    //产品设定的数据类型不规范，所以还需要处理下 逻辑类型的字段
    h3ui.models.t_cost_center.item.del = h3ui.models.t_cost_center.item.del == 1;

    h3ui.widgets.CustomModal2.props.title = "修改成本中心";
    h3ui.widgets.CustomModal2.props.visible = true;

    //表单必填表示,添加list
    let filedRequest=['FormModelItem26','FormModelItem27','FormModelItem28'];

    //模型领域字段必填
    let modelRequest=['organization_id','member_id','name'];


}


// 提交 成本中心
function submitCenter() {
    h3ui.models.t_cost_center.submitBO().then(res => {

        reloadList("FormList7");
        h3ui.widgets.CustomModal2.props.visible = false;
    });
}




//设置必填信息
function setRequest(filedRequest,modelRequest,modeName){
    //设置表格必填标识
 /*   for (let filedRequestElement of filedRequest) {
        h3ui.widgets.filedRequestElement.props.required = true;
    }*/
    filedRequest.forEach(a=>{
        h3ui.widgets[a].props.required = true;
    })

    //设置模型领域必填
    for (let modelRequestElement of modelRequest) {
        h3ui.models.modeName._propDatas.get(modelRequestElement).required = true; // 必填
    }
}


//==================待发货列表=========


//=========== 待收货===============


// ========== 黑名单管理 ===============

// 打开黑名单管理
function openBlackModel() {

    console.log("打开黑名单管理");

    var rows = h3ui.widgets.FormList13.props.selectedRow;


    if (rows.length != 1) {
        h3ui.$message.info("请选择仅一条数据");
        return;
    }

    var row = rows[0];


    var dept = {name: row.name, id: row.id, type: 1};

    //黑名单模型
    var blackMode = h3ui.models.t_black_list;
    //初始化
    blackMode.newItem();

    h3ui.widgets.Label6.props.content = "客户名称：".concat(dept.name);

    blackMode.item.client_organid = dept.id;
    blackMode.item.client_organ_name = dept.name;


    var transfer = h3ui.widgets.Transfer1.props;
    transfer.dataSource = [];
    transfer.value = null;


    h3ui.services.getOrgTransferInfo(dept).then(res => {
        console.log(res)
        if (res.success) {
            //穿梭框复制
            transfer.dataSource = res.data.leftTransferList || [];
            transfer.value = res.data.rightTransferList || [];
            //绑定黑名单 id
            blackMode.item.id = res.data.id;

        } else {
            h3ui.$message.info(res.errMessage || "获取数据异常");
        }
    });
    h3ui.widgets.CustomModal3.props.visible = true;
}

// 提交黑名单
function submitBlack() {
    // 获取穿梭框
    var transfer = h3ui.widgets.Transfer1.props;

    //黑名单模型
    var blackMode = h3ui.models.t_black_list;

    //判断
    var leftTransf = a => transfer.value.includes(a.key);

    //过滤并赋值 黑名单组织
    blackMode.item.organ_ids = transfer.dataSource.filter(leftTransf).map(a => a.key).join();
    blackMode.item.organ_name = transfer.dataSource.filter(leftTransf).map(a => a.title).join();

    //提交黑名单
    blackMode.submitBO().then(res => {

        reloadList("FormList13");

        //关闭对话框
        h3ui.widgets.CustomModal3.props.visible = false;


    });


}


// ===========成本中心关系==========

//新增成本中心
function openCreateCostRelation() {
    var costRelationMode = h3ui.models.t_cost_center_relation;

    costRelationMode.newItem();



    h3ui.widgets.CustomModal4.props.title = "创建成本中心关系";

    h3ui.widgets.CustomModal4.props.visible = true;



    let  filedRequest=['FormModelItem88','FormModelItem59','FormModelItem63-label']
    let  modelRequest=['org','member_id','cost_center_id'];

    setRequest(filedRequest,modelRequest,'t_cost_center_relation');

}

//修改成本中心
function openUpdateCostRelation() {
    console.log("成本中心关系");
    h3ui.widgets.CustomModal4.props.title = "修改成本中心关系";
    var rows = h3ui.widgets.FormList12.props.selectedRow;


    if (rows.length != 1) {
        h3ui.$message.info("请选择仅一条数据");
        return;
    }

    var row = rows[0];


    var costRelationMode = h3ui.models.t_cost_center_relation;

    costRelationMode.newItem();


    costRelationMode.item.id = row.id;

    costRelationMode.item.cost_center_id = row.cost_center_id;

    h3ui.widgets.CustomModal4.props.visible = true;

    let  filedRequest=['FormModelItem88','FormModelItem59','FormModelItem63-label']
    let  modelRequest=['org','member_id','cost_center_id'];

    setRequest(filedRequest,modelRequest,'t_cost_center_relation');

}


//提交成本中心
function submitCostRelation() {


    var costRelationMode = h3ui.models.t_cost_center_relation;

    //提交
    costRelationMode.submitBO().then(res => {

        reloadList("FormList12");
        //关闭对话框
        h3ui.widgets.CustomModal4.props.visible = false;


    });

}

//创建平台客户关系框重置
function resetPlatRole() {
    h3ui.widgets.StaffSelector30.props.value = [];
    h3ui.widgets.StaffSelector31.props.value = [];
}


//待收货--订单列渲染
function sourceJudge(evt) {
    if (evt.data.row.client_order_goods_id) {
        evt.data.components[0].props.content = "外部来源";
    } else {
        evt.data.components[0].props.content = "平台订单";
    }
    console.log(evt);
}

function custListLoad(evt) {
    console.log(evt);

    var data = JSON.parse(JSON.stringify(evt.data.filter));

    var order_customer_goods_status = data.order_customer_goods_status;

    if (order_customer_goods_status instanceof Array) {
        data.order_customer_goods_status = order_customer_goods_status.join();
    }

    var createdTime = data.createdTime;
    delete data.createdTime;
    if (createdTime != null && createdTime.length > 1) {
        data.startTime = createdTime[0];
        data.endTime = createdTime[1];
    }


    var param = {};

    Object.keys(data).forEach(a => {
        param[toHump(a)] = data[a];
    })


    param.pageIndex = evt.data.pageIndex - 1;
    param.pageSize = evt.data.pageSize;


    var url = "/api/launcher/ordercenter/application/invoke?action=/CustomerDeliveryService/customerDeliveryList";

    console.log("123213123", param);
    axiosService(url, param)
        .then(res => {
            console.log(res);
            if (res.success) {
                evt.node.props.dataSource = {items: res.data.data, total: res.data.total};
            } else {
                h3ui.$message.info(res.errMessage || "修改失败")
            }
        })

}


function toHump(code) {
    if (code.includes("_")) {

        var ac = code.split("_");

        if (ac.length > 1) {
            for (var i = 1; i < ac.length; i++) {
                ac[i] = ac[i].charAt().toUpperCase().concat(ac[i].substr(1));
            }
            code = ac.join("");
        }

    }
    return code;
}


// 行单击事件
function formListRowClick(evt) {
    // debugger;
    console.log(evt);

    // 获取单击的列
    let {id, key} = evt.data.col;
    let colValue = evt.data.row[key];
    if (colValue instanceof Array) {
        if (colValue.length == 0) {
            return;
        }
        colValue = colValue[0].id;
    }
    var param = {
        clickcloumn: colValue,
        mode: "detail",
        link: "platform_cust_mana"
    };
    //跳转到需求单详情
    if ("ModelTableColumn20" == id) {
        toModePage("demandPoolDetail", param, "demandpool");

    } else if ("ModelTableColumn38" == id) {
        let param = {
            clickcloumn: colValue,
            link: "platform_cust_mana"
        }
        toModePage("inquiry_detail", param, "sourcingcenter");

    } else if (["ModelTableColumn102", "ModelTableColumn174", "ModelTableColumn106"].includes(id)) {
        toModePage("customer_detail_new", param, "ordercenter");

    } else if (["ModelTableColumn104", "ModelTableColumn183", "ModelTableColumn107"].includes(id)) {
        toModePage("scmdetail", param, "ordercenter");
    }
}


function formListColRender(evt) {
    // console.log(evt, "formListColRender");
    let {components, col, row, formatText} = evt.data;
    let value = row[col.key];
    let colId = col.id;
    //需求状态
    if (colId == "ModelTableColumn21") {
        setDemandPoolStatusStyle(components, value, formatText);
    } else if (colId == "ModelTableColumn44") {
        //报价状态
        setQuotationGoodsStatus(components, value, formatText);
    } else if (['ModelTableColumn207', 'ModelTableColumn208', 'ModelTableColumn182','ModelTableColumn428','ModelTableColumn675','ModelTableColumn616'].includes(colId)) {
        //订单商品状态
        components[0] = {
            type: 'Tag', props: {
                text: formatText,
                color: '#009688'
            }
        };

    } else if ("ModelTableColumn37" == colId) {
        //报价次数/参与次数渲染
        components[0].props.content = row.quote_count + "/" + row.partake_count;
    } else if (["ModelTableColumn39", "ModelTableColumn218", "ModelTableColumn219"].includes(colId)) {
        //整单,多次,密封
        setStrategyStyle(components, formatText);

    } else if (["ModelTableColumn91", "ModelTableColumn121"].includes(colId)) {
        //包装
        components[0].props.content = (row.package_quantity || 0) + "/" + row.package_unit;
    }


}

// 设置需求池状态样式
function setDemandPoolStatusStyle(components, value, formatText) {
    var color = ['#52C419', '#1890FF', '#F5222D', '#d9d9d9', '#FAAD15', '#1890FF', '#FAAD15'][value];
    components[0] = {
        type: 'Tag',
        props: {
            text: formatText,
            color
        }
    };
}


// 设置报价商品状态样式
function setQuotationGoodsStatus(components, value, formatText) {
    var color = ['#52C419', '#F5222D', '#F5222D', '#FAAD15', '#FAAD15', '#1890FF', '#d9d9d9', '#d9d9d9'][value];
    components[0] = {
        type: 'Tag',
        props: {
            text: formatText,
            color
        }
    };
}

// 设置 //整单,多次,密封 样式
function setStrategyStyle(components, text) {

    let color = text == '是' ? '#ff0000' : '#000000';

    components[0] = {
        type: "Label",
        props: {
            content: text,
            fontColor: color
        }
    };
}


// 单元格文本渲染
function cellRender(evt) {
    // 获取模型表格id

    // 获取表单id
    let {components, col, row, formatText} = evt.data;
    let value = row[col.key];
    let nodeId = evt.data.col.node.id;

    if (formatText instanceof Array) {
        formatText = formatText[0].id;
        components[0].props.content = formatText;
    }


}

// 导出
function exportQuotation(evt) {
    debugger;
    let formlistId = '';//列表ID
    //未参与报价导出按钮
    if(evt.node.id == 'Buttons64' ){
        formlistId = 'FormList10';
    }
    let length = h3ui.widgets[formlistId].props.selectedRowKeys.length;
    if (length == 0) {
        h3ui.$message.warn('请选择要导出的数据');
        return false;
    }
    // 显示对话框
    h3ui.widgets.RadioGroup2.props.value = 'xlsx';
    h3ui.widgets.Modal1.props.visible = true;
    let buttenId = evt.node.id;
    localStorage.setItem("buttenId",buttenId);//放入缓存
}

// 确认导出
function confirmExportQuotationGoodstWithAll(evt) {
    debugger
    let buttenId = localStorage.getItem("buttenId");//取数据
    localStorage.removeItem("buttenId");//清缓存
    let formlistId = '';//列表ID
    let serviceId = '';//导出接口
    let exportType = '';


    //未参与报价导出按钮
    if (buttenId == 'Buttons64') {
        formlistId = 'FormList10';
    }


    if (!h3ui.widgets.RadioGroup2.props.value) {
        h3ui.$message.warn('请选择要导出的格式');
        return false;
    }

    // 关闭对话框
    h3ui.widgets.Modal1.props.visible = false;
    // 设置要导出的文件
    // 获取要导出的数据
    let rowKeys = h3ui.widgets[formlistId].props.selectedRowKeys;
    // 获取到导出的格式
    let type = h3ui.widgets.RadioGroup2.props.value;
    let param = {
        data: {ids: rowKeys, fileType: type},
        schemaCode: h3ui.widgets[formlistId].props.bindingModel.domainCode
    }
    var url = "/api/launcher/ordercenter/application/invoke?action=/CustomerDeliveryService/exportCustomerReceived";

    axiosService(url, param).then(res => {
        console.log(res);
        if (res.success) {
            h3ui.widgets.gmNoticeBar1.props.visible = true;
        } else {
            h3ui.$message.warn('暂无数据');
        }
    })

}

//牧原操作事件开始
//自定义虚牧原专场订单加载事件
function custInventedQuotedList(evt) {
    debugger;
    customConditionLoad(evt, [], "inventedQuotedList");
    h3ui.widgets[evt.node.id].props.dataSource={items:[],total:0};
}


//获取系统加载列表服务
function customConditionLoad(evt, custCondArr, custListBo) {
    let {pageIndex, pageSize, filter} = evt.data;
    debugger;
    let listId = evt.node.id;
    let schemaCode = h3ui.widgets[listId].props.bindingModel.schemaCode;
    let dataSource = h3ui.models[schemaCode];
    filter = JSON.parse(JSON.stringify(filter)) || {};

    let condition = dataSource.toQueryCondition(filter, dataSource.schema);

    console.info(filter);

    let placeOrderTimeSelect = h3ui.widgets.Select78.props.value || '';
    let invoiceStatus = h3ui.widgets.Select80.props.value || '';

    let param = {
        erpPo: filter.erp_po,
        invoiceStatus: invoiceStatus,
        orderCustomerStatus: filter.order_customer_status,
        placeOrderFullname:filter.place_order_fullname,
        placeOrderTime:filter.createdTime,
        placeOrderTimeSelect:placeOrderTimeSelect,
        address:filter.address,
        currentLevel: false,
        page: pageIndex,
        pageIndex: pageIndex - 1,
        pageSize: pageSize,
        schemaCode: schemaCode,
        size: pageSize,
        tree: false,


    }
    //调用接口api
    let url = "/api/launcher/" + h3ui.appInfo.appCode + "/application/invoke?action=/MuYuanVendorService/VendorOrder";
    axiosService(url,param).then(res=>{
        if(res.success){
            console.info(res.data);
            h3ui.widgets[listId].props.dataSource ={
                items: res.data.data,
                total: res.data.total
            }

        }
    })

}




//自定义虚牧原专场商品加载事件
function custGoodsQuotedList(evt) {
    debugger;
    customerGoodsConditionLoad(evt, [], "inventedQuotedList");
    h3ui.widgets[evt.node.id].props.dataSource={items:[],total:0};
}



//获取系统加载列表服务订单商品
function customerGoodsConditionLoad(evt, custCondArr, custListBo) {
    let {pageIndex, pageSize, filter} = evt.data;
    debugger;
    let listId = evt.node.id;
    let schemaCode = h3ui.widgets[listId].props.bindingModel.schemaCode;
    let dataSource = h3ui.models[schemaCode];
    filter = JSON.parse(JSON.stringify(filter)) || {};

    let condition = dataSource.toQueryCondition(filter, dataSource.schema);

    console.info(filter);

    let placeOrderTimeSelect = h3ui.widgets.Select78.props.value || '';
    let invoiceStatus = h3ui.widgets.Select80.props.value || '';

    let  ifClarifyTips= h3ui.widgets.FormModelItem472.props.value || '';
    let ifUploadImage=h3ui.widgets.FormModelItem474.value || '';
    let param = {
        erpPo: filter.erp_po,
        invoiceStatus: invoiceStatus,
        orderVendorStatus: filter.order_customer_goods_status,
        placeOrderFullname:filter.place_order_fullname,
        placeOrderTime:filter.place_order_time,
        placeOrderTimeSelect:placeOrderTimeSelect,
        address:filter.address,
        sku:filter.sku,
        name:filter.name,
        brand:filter.brand,
        model:filter.model,
        id:filter.id,
        ifClarifyTips:ifClarifyTips,
        currentLevel: false,
        vendorOrganizationName:filter.vendor_organization_name,
        ifUploadImage:filter.if_upload_image,
        page: pageIndex,
        pageIndex: pageIndex - 1,
        pageSize: pageSize,
        schemaCode: schemaCode,
        size: pageSize,
        tree: false,


    }
    //调用接口api
    let url = "/api/launcher/" + h3ui.appInfo.appCode + "/application/invoke?action=/MuYuanVendorService/CustomerGoods";
    axiosService(url,param).then(res=>{
        if(res.success){
            console.info(res.data);
            h3ui.widgets[listId].props.dataSource ={
                items: res.data.data,
                total: res.data.total
            }

        }
    })

}

//牧原操作事件结束


//首次进入事件
function intoOrder(){
    h3ui.widgets.RadioGroup3.props.value  = "order"
}


//切换列表
function checkval(evt) {
    let type='order';
    let val='';
    if (evt == type){
         val = evt;
    } else {
         val = h3ui.widgets.RadioGroup3.props.value;
    }

    if (val == type) {
        h3ui.widgets.GridCol14.props.visible.display = "";
        h3ui.widgets.GridCol16.props.visible.display = "none";
    } else {
        h3ui.widgets.GridCol14.props.visible.display = "none";
        h3ui.widgets.GridCol16.props.visible.display = "";
    }

}

//打开物流弹框
function openDetailModal(evt) {
    if (evt.node.id =='FormList19'){
        actionClick(evt);
    }else {
        let waybillNum = evt.data.row.waybill;//获取物流单号
        if (!waybillNum){
            h3ui.$message.error('暂无单号');
            return;
        }
        logisticsMessage(evt);
    }
}


// 操作栏
function actionClick(evt) {
    console.log(evt);
    let id =evt.data.row.id;
    let  param={
        pageIndex :1,
        pageSize:100,
        id:id
    }
    //调用接口api
    let url = "/api/launcher/ordercenter/application/invoke?action=/CustomerDetailService/customerLogistics";
    axiosService(url,param).then(res=>{
        if(res.success){
            console.info(res.data);
            h3ui.widgets.FormList21.props.dataSource ={
                items: res.data.data,
                total: res.data.total
            }

        }
    })
    h3ui.widgets.Modal2.props.visible = true;
}


//查看物流详情
function logisticsMessage(evt){
    debugger;
    h3ui.widgets.Label15.props.content='物流名称';
    h3ui.widgets.Label16.props.content='物流单号';

    if(evt.data.col.key == 'waybill'){
        //物流详情页面加载数据
        h3ui.widgets.Modal4.props.visible = true;
        let waybillNum = evt.data.row.waybill;//获取物流单号
       if (!waybillNum){
           h3ui.widgets.Timeline2.props.userData = [{
               "color":"",
               "content": '查不到物流信息',
           }];//获取对应数据----缺少数据调用
           return;
       }
        let phone = evt.data.row.phone;//获取手机号后四位
        let phones = '';
        if(phone){
            phones = phone.substring(phone.length-4)
        }else{
            phones = ''
        }

        let param = {
            waybillNum:waybillNum,
            phone:phones,
            //测试数据
            /* waybillNum:'JD0049806519170',
            phone:'6380', */
        }
        //物流公共订单接口
        let url = "/api/launcher/ordercenter/application/invoke?action=/LogisticsService/queryLogistics";

        axiosService(url,param).then(res => {
            if(res.success && res.data){
                //时间轴数据填充
                let jsondata = res.data.resLogistics.showapi_res_body.data;//获取物流信息
                let content = '';
                let userData = {};//每条数据内容
                let listdata = [];//进度条全部内容
                for(let i in jsondata){
                    content = jsondata[i].time+' :  ' + jsondata[i].context;
                    userData = {
                        "color":"green",
                        "content": content
                    }
                    listdata.push(userData);
                }
                if (jsondata.length <= 0){//如果没有物流记录则返回“暂无记录"
                    h3ui.widgets.Timeline2.props.userData = [{
                        "color":"",
                        "content": '查不到物流信息',
                    }];//获取对应数据----缺少数据调用
                    h3ui.widgets.GridCol20.props.visible.display = '';//是否显示”暂无记录“(无数据)
                    h3ui.widgets.Label16.props.content = evt.data.row.waybill;//物流单号
                    return;
                }
                if(res.data.resLogistics.showapi_res_body.expTextName){//物流名称
                    h3ui.widgets.Label15.props.content = res.data.resLogistics.showapi_res_body.expTextName;
                }
                if(res.data.resLogistics.showapi_res_body.mailNo){//物流单号
                    h3ui.widgets.Label16.props.content = res.data.resLogistics.showapi_res_body.mailNo;
                }
                h3ui.widgets.GridCol20.props.visible.display = 'none';//是否显示”暂无记录“(有数据)
                h3ui.widgets.Timeline2.props.userData = listdata;//获取对应数据----缺少数据调用
            }else{
                h3ui.$message.error('接口调用失败')
            }
        });
    }
}


//确认收货
function check() {
    let ids = new Array();
    let keys = h3ui.widgets.FormList19.props.selectedRowKeys;
    if(keys && keys.length == 0){  //未选中状态
        h3ui.$message.error('未选择数据行');
        return;
    } else if(keys && keys.length == 1){ //选中一条
        let listdata1 =  h3ui.widgets.FormList19.props.selectedRow[0];
        if(listdata1.quantity_shipped - listdata1.quantity_received <= 0){
            h3ui.$message.error('暂无可收货数量');
            return;
        }
        h3ui.widgets.Modal5.props.visible = true;
        let items = h3ui.widgets.FormList19.props.dataSource.items;
        // 获取当前的列表数据
        let BO = items.find(res => res.id === keys[0]);
        // 给弹框赋值
        if(BO.quantity_received == 0 || BO.quantity_received == ''){
            BO.quantity_received = '0';
        }
        h3ui.models.t_order_customer_goods.item = BO;
        h3ui.widgets.FormModelItem484.props.value = listdata1.quantity_shipped - listdata1.quantity_received;
    } else { //选中多条
        ids = [];
        h3ui.widgets.FormList19.props.selectedRow.map((items) => {
            ids.push(items.id);
        });
        h3ui.$confirm({
            title: '确认将这批商品全部收货?',
            onOk() {
                tkSubmit(ids);
            },
            cancelText: '',
            onCancel() {

            },
        });
    }
}

// 确认全部收货
function tkSubmit(ids) {
    let url = "/api/launcher/ordercenter/application/invoke?action=/CustomerDeliveryService/customerBatchReceipt";

    var params = {
        ids:ids
    }
    axiosService(url,params).then(res => {
        console.log(res,'res1.....');
        if(res.success && res.data){
            h3ui.$message.success('收货成功！');
            doReloadList('FormList19');
        }else {
            h3ui.$message.error(res.errMessage  != null ? res.errMessage:"收货失败" );
        }
    })
}


// 分批待收货确认收货
function saleSubmit() {
    debugger;
    let quantity = h3ui.widgets.InputNumber287.props.value;//输入的收货数量
    let params = {
        id:h3ui.widgets.FormList19.props.selectedRowKeys[0],
        quantity:quantity ,
    }
    let listdata1 =  h3ui.widgets.FormList19.props.selectedRow[0];//判断收货数量是否大于可收；
    let ablenum = listdata1.quantity_shipped - listdata1.quantity_received;
    if( quantity > ablenum){
        h3ui.$message.error('收货数量不能大于可收货数量：'+ ablenum);
        return;
    }
    let url = "/api/launcher/ordercenter/application/invoke?action=/CustomerDeliveryService/customerPartReceipt";

  axiosService(url,params).then(res => {  //接口名称
        if(res.success && res.data){
            h3ui.widgets.Modal5.props.visible = false;
            h3ui.$message.success('收货成功！');
            doReloadList('FormList1');
        } else {
            h3ui.$message.error(res.errMessage  != null ? res.errMessage:"收货失败" );
        }
    })
}
